17.2 Wait Queue Initialization
The initial statement within sched_init(), BUG_ON(&idle_sched_class + 1 != &fair_sched_class || ...), ensures that the physical memory storing the scheduling classes has not suffered data corruption or misalignment. If the system is compiled as a symmetric multiprocessing topology (configured via CONFIG_SMP), it additionally validates the memory alignment of the stop_sched_class zone.
Following these integrity validations, the task scheduler initialization routine invokes wait_bit_init(), which routes execution to init_waitqueue_head() to bootstrap the global wait queue headers and their associated spinlocks. These specialized wait queues form the baseline data structures consumed by the process sleep (wait) and wakeup (wake_up) mechanisms. The definition of these routines is implemented as follows:
void __init wait_bit_init(void)
{
int i;
for (i = 0; i < WAIT_TABLE_SIZE; i++)
init_waitqueue_head(bit_wait_table + i);
}
#define init_waitqueue_head(wq_head) \
do { \
static struct lock_class_key __key; \
__init_waitqueue_head((wq_head), #wq_head, &__key); \
} while (0)
void __init_waitqueue_head(struct wait_queue_head *wq_head,
const char *name, struct lock_class_key *key)
{
spin_lock_init(&wq_head->lock);
lockdep_set_class_and_name(&wq_head->lock, key, name);
INIT_LIST_HEAD(&wq_head->head);
}
These code elements reside across the source files git/include/linux/wait.h and git/kernel/sched/wait.c. The linked list head initialization macro INIT_LIST_HEAD() is declared within the file git/include/linux/list.h.